package com.furnitur.core.mapper.cart;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.furnitur.core.entity.cart.Cart;
import com.furnitur.modules.portal.vo.cart.CartVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CartMapper extends BaseMapper<Cart> {
    
    /**
     * 查询用户购物车列表
     */
    @Select("SELECT c.id, c.furniture_id, f.name as furniture_name, " +
            "f.image_url, f.price, c.quantity, f.stock, " +
            "f.merchant_id, u.username as merchant_name " +
            "FROM cart c " +
            "LEFT JOIN furniture f ON c.furniture_id = f.id " +
            "LEFT JOIN users u ON f.merchant_id = u.id " +
            "WHERE c.user_id = #{userId}")
    List<CartVO> selectUserCartItems(@Param("userId") Long userId);

    @Delete("DELETE FROM cart WHERE furniture_id IN (SELECT id FROM furniture WHERE merchant_id = #{merchantId})")
    int deleteByMerchantId(@Param("merchantId") Long merchantId);
    
}